package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    List<User> selectPage(UserDto userDto);

    @Insert("insert into user(username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time)" +
            " VALUE (#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void insert(User user);

    void delectByIds(List<Integer> ids);

    @Select("SELECT * from user where id = #{id}")
    User selectById(Integer id);

    void update(User user);

    @Select("select * from  user")
    List<User> list();

    @Select("select u.* from user u left join role r on u.role_id = r.id where status = 1 and r.label = #{roleLabel}")
    List<User> listOfLabel(String roleLabel);

    @Select("select * from user where dept_id = #{deptId}")
    List<User> listOfDeptId(Integer deptId);

    @Select("select u.*,r.label role_label from user u left join role r on u.role_id = r.id where u.username = #{username}")
    User selectByUsername(String username);
}
